package com.wxw.gulidemo.controller.front;/**
 * @author by xxz
 * @date 2022/6/16
 */

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wxw.gulidemo.R;
import com.wxw.gulidemo.entity.EduCourse;
import com.wxw.gulidemo.entity.EduTeacher;
import com.wxw.gulidemo.service.IEduCourseService;
import com.wxw.gulidemo.service.IEduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.sql.Wrapper;
import java.util.List;
import java.util.Map;

/**
 * @Description

 * @author by xxz

 * @date 2022/6/16

 * @throws
 */
@RestController
@CrossOrigin
@RequestMapping("/eduService/teacherFront")
public class TeacherFrontController {

    @Autowired
    private IEduTeacherService eduTeacherService;

    @Autowired
    private IEduCourseService eduCourseService;

    //名师列表(带分页)
    @PostMapping("/getTeacherFrontPageList/{page}/{limit}")
    public R getTeacherFrontPageList(@PathVariable Long page,
                                     @PathVariable Long limit){

        Page<EduTeacher> teacherPage = new Page<>(page, limit);
        Map<String,Object> map = eduTeacherService.getTeacherFrontPageList(teacherPage);
        //返回分页中的所有数据
        return R.ok().data(map);
    }

    //名师详情信息展示
    @GetMapping("/getTeacherInfo/{id}")
    public R getTeacherInfo(@PathVariable String id){
        EduTeacher teacher = eduTeacherService.getById(id);
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id",id);
        List<EduCourse> courseList= eduCourseService.list(wrapper);
        return R.ok().data("teacher",teacher).data("courseList",courseList);
    }

}
